<!-- BEGIN PAGE HEADER-->
<?php $this->load->view('partials/breadcrumb.tpl') ?>
<!-- END PAGE HEADER-->

<div class="row">
    <div class="col-xs-12">
        <!-- Begin: life time stats -->
        <div class="portlet">
            <?= form_open('', Array('class' => 'form-inline', 'role' => 'form')) ?>
            <?= search_form_input('id', filterValue('id'), '商品ID', 'class="form-control input-xs"'); ?>
            <?= search_form_input('product_name', filterValue('product_name'), '商品名称', 'class="form-control input-xs"'); ?>
            <?= search_form_dropdown('purchaser_id', array('' => '选择采购人...') + $allPurchaser, filterValue('purchaser_id'), '采购人', 'class="form-control input-xs"'); ?>

            <div style="clear:both;height:14px;"></div>
            <?= search_form_input('product_number_perpage', filterValue('product_number_perpage'), '每页显示条数', 'class="form-control input-xs"'); ?>
            <?= search_form_dropdown('product_order_type', array('' => '排序方式...') + MStorageProduct::getOrderType(), filterValue('product_order_type'), '排序', 'class="form-control input-xs"'); ?>
            <div class="input-group input-large date-picker input-daterange" data-date="" data-date-format="yyyy-mm-dd">
                <input type="text" class="form-control" name="product_create_time_begin" value="<?= filterValue('product_create_time_begin') ?>" placeholder="开始时间" autoComplete="off">
                <span class="input-group-addon">to </span>
                <input type="text" class="form-control" name="product_create_time_end" value="<?= filterValue('product_create_time_end') ?>" placeholder="结束时间" autoComplete="off">
            </div>

            <button type="button" class="btn default" id="reset">重置条件</button>
            <button type="submit" class="btn green about_search">搜索 <i class="fa fa-search"></i></button>

            <?= form_close() ?>
            <div class="portlet-body">
                <div class="row">
                    <div class="col-xs-12">
                        <div class="table-scrollable">
                            <table class="table table-striped table-bordered table-hover">
                                <thead class="flip-content">
                                <tr>
                                    <th width="5%">ID</th>
                                    <th width="8%">商品名称</th>
                                    <th width="8%">采购人</th>
                                    <th width="6%">商品单价</th>
                                    <th width="6%">产品单位</th>
                                    <th width="8%">产品类型</th>
                                    <th width="5%">当前库存</th>
                                    <th width="12%">备注</th>
                                    <th>创建时间</th>
                                    <th width="8%">修改历史</th>
                                    <th width="22%">操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                <?php foreach ($list as $v) { ?>
                                    <tr>
                                        <td class="numeric"><?= $v->id ?></td>
                                        <td class="numeric"><?= htmlspecialchars($v->product_name) ?></td>
                                        <td class="numeric"><?= htmlspecialchars($allPurchaser[$v->purchaser_id]) ?></td>
                                        <td class="numeric"><?= $v->price ?></td>
                                        <td class="numeric"><?= htmlspecialchars($v->unit) ?></td>
                                        <td class="numeric"><?= htmlspecialchars($v->product_type) ?></td>
                                        <td class="numeric"><?= $v->number?'<span class="label label-success">'.$v->number.'</span>':'<span class="label label-warning">暂无库存</span>' ?></td>
                                        <td class="numeric"><?= htmlspecialchars($v->remark) ?></td>
                                        <td class="numeric"><?= date('Y-m-d H:i', $v->create_time) ?></td>
                                        <td class="numeric"><button data-id="<?= $v->id ?>"
                                                                      data-route="<?= $this->_thisModule . $this->_thisController . '/edit' ?>"
                                                                      class="btn btn-sm btn-success edit-his">修改记录
                                            </button></td>
                                        <td class="numeric text-center">
                                            <div class="btn-group btn-group-solid">
                                                <a href="<?= site_url($thisModule . $thisController . '/view/' . $v->id) ?>" class="btn btn-sm blue <?= $p->read ? '' : 'disabled' ?>"><i class="fa fa-play"></i> 查看
                                                </a>
                                                <a href="<?= site_url($thisModule . $thisController . '/edit/' . $v->id) ?>" class="btn btn-sm purple <?= ($p->edit && $this->_user->id == $v->purchaser_id)  ? '' : 'disabled' ?>">
                                                    <i class="fa fa-edit"></i> 编辑
                                                </a>

                                                <a href="<?= site_url('/storage/warehouse/add_in/'.$v->id) ?>" class="btn btn-sm yellow-gold">
                                                    <i class="fa fa-plus-square-o"></i> 入库
                                                </a>
                                                <a href="<?= site_url('/storage/warehouse/add_out/'.$v->id) ?>" class="btn btn-sm red">
                                                    <i class="fa fa-minus-square"></i> 出库
                                                </a>
                                            </div>
                                        </td>
                                    </tr>
                                <?php } ?>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-xs-12 text-right">
                        <?= $pagination ?>
                    </div>
                </div>
            </div>
        </div>
        <!-- End: life time stats -->
    </div>
</div>

<!--  log-modal  -->
<div class="modal fade logModal">
    <div class="modal-dialog modal-lg" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                            aria-hidden="true">×</span></button>
                <h4 class="modal-title" id="gridModalLabel">操作记录</h4>
            </div>
            <div class="modal-body" id="log-content">

            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
            </div>
            <?= form_close() ?>
        </div>
    </div>
</div>

<script>
    $(document).ready(function () {
        var editHis = $(".edit-his");
        editHis.click(function () {
            var id = this.dataset.id;
            var route = this.dataset.route;
            $.ajax({
                url: "<?= site_url('storage/warehouse/ajaxHis') ?>",
                method: "POST",
                data: {'id': id, 'route': route},
                dataType: "json",
                success: function (res) {
                    console.log(res);
                    var html = '';
                    if (!res.length) {
                        toastr.error('暂无修改记录！', '暂无')
                    } else {
                        for (var i = 0; i < res.length; i++) {
                            html += '<div class=""><p class="bg-warning" style="padding: 2px 4px;"> <span> '+res[i].user_name+' </span>于 <span style="color:#2120ff">'+res[i].create_time+'</span> <span>操作：</span><span style="color:red;">'+res[i].content+'</span><p></div>'
                        }
                        $("#log-content").html(html);
                        $('.logModal').modal('show');
                    }
                },
                fail: function (res) {
                    console.log(res);
                }
            });
        });

        $("#reset").click(function () {
            var SelectArr = $("select");
            $("input[type='text']").val('');
            SelectArr.val('');
        });
    });
</script>